package com.zkthink.ceres.order.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkthink.base.R;
import com.zkthink.cache.repository.RedisRepositoryImpl;
import com.zkthink.ceres.member.entity.Member;
import com.zkthink.ceres.member.service.MemberService;
import com.zkthink.ceres.order.constants.CommentConstant;
import com.zkthink.ceres.order.dao.*;
import com.zkthink.ceres.order.dto.comment.*;
import com.zkthink.ceres.order.entity.*;
import com.zkthink.ceres.order.enums.CommentTypeEnum;
import com.zkthink.ceres.order.enums.SensitiveKeywordAction;
import com.zkthink.ceres.order.service.CommentService;
import com.zkthink.base.service.SuperServiceImpl;
import com.zkthink.ceres.order.vo.OrderProductVO;
import com.zkthink.ceres.order.vo.comment.CommentKeywordVO;
import com.zkthink.ceres.order.vo.comment.CommentPageVO;
import com.zkthink.ceres.order.vo.comment.CommentVO;
import com.zkthink.ceres.product.entity.Product;
import com.zkthink.ceres.product.service.ProductService;
import com.zkthink.ceres.store.entity.Store;
import com.zkthink.ceres.store.service.StoreService;
import com.zkthink.ceres.wordfilter.WordContext;
import com.zkthink.ceres.wordfilter.WordFilter;
import com.zkthink.context.BaseContextHandler;
import com.zkthink.database.mybatis.conditions.Wraps;
import com.zkthink.dozer.DozerUtils;
import com.zkthink.exception.BizException;
import com.zkthink.exception.code.ExceptionCode;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 业务实现类
 * 评价表
 * </p>
 *
 * @author JustArgo
 * @date 2020-07-12
 */
@Slf4j
@AllArgsConstructor
@Service
public class CommentServiceImpl extends SuperServiceImpl<CommentMapper, Comment> implements CommentService {

    private OrderProductMapper orderProductMapper;

    private OrderMapper orderMapper;

    private DozerUtils dozerUtils;

    private MemberService memberService;

    private StoreService storeService;

    private RedisRepositoryImpl redisRepository;

    private CommentSensitiveRelateMapper commentSensitiveRelateMapper;

    private CommentKeywordRelateMapper commentKeywordRelateMapper;

    private SensitiveKeywordMapper sensitiveKeywordMapper;

    private CommentLikeMapper commentLikeMapper;

    private ProductService productService;



    @Override
    public R<QueryCommentPageDTO> findCommentList(AdminQueryCommentDTO dto) {
        QueryCommentPageDTO pageDTO = new QueryCommentPageDTO();

        Random random = new Random();
        Integer start = (dto.getPageIndex() - 1) * dto.getPageSize();
        dto.setStart(start);

        Integer total = baseMapper.findAdminCommentListCount(dto);
        List<CommentDTO> dtoList = baseMapper.findAdminCommentList(dto);
        for (CommentDTO commentDTO : dtoList) {
            Comment additionalComment = baseMapper.selectOne(Wraps.<Comment>lbQ().eq(Comment::getBizType, CommentTypeEnum.ADDITIONAL.getCode()).eq(Comment::getIsDelete, false).eq(Comment::getParentId, commentDTO.getId()));
            commentDTO.setAdditionalComment(additionalComment);

            Member member = memberService.getById(commentDTO.getMid());
            if (member != null) {
                commentDTO.setMemberAccount(member.getNickname() + "_" + member.getOpenid());
            } else {
                commentDTO.setMemberAccount("未知");
            }

            Product product = productService.getById(commentDTO.getProductId());
            if(product!=null){
                commentDTO.setProductName(product.getProductName());
            }

            Store store = storeService.getById(commentDTO.getStoreId());
            if (store != null) {
                commentDTO.setStoreName(store.getStoreName());
            }

            List<Long> relateCommentIdList = new ArrayList<>();
            relateCommentIdList.add(commentDTO.getId());
            if (additionalComment != null) {
                relateCommentIdList.add(additionalComment.getId());
            }

            List<CommentSensitiveRelate> relateList = commentSensitiveRelateMapper.selectList(Wraps.<CommentSensitiveRelate>lbQ()
                    .in(CommentSensitiveRelate::getCommentId,relateCommentIdList));
            if(relateList.size()>0){
                List<SensitiveKeyword> sensitiveKeywordList = sensitiveKeywordMapper.selectList(Wraps.<SensitiveKeyword>lbQ()
                        .eq(SensitiveKeyword::getEnabled,true)
                        .in(SensitiveKeyword::getId,relateList.stream().map(n -> n.getSensitiveKeywordId()).collect(Collectors.toList())));
                commentDTO.setSensitiveKeywordList(sensitiveKeywordList.stream().map(n -> n.getSensitiveKeyword()).collect(Collectors.toList()));
            }
        }

        pageDTO.setTotal(total);
        pageDTO.setCommentDTOList(dtoList);

        return R.success(pageDTO);
    }

    @Override
    public R<Boolean> handleComment(HandleCommentDTO handleCommentDTO) {
        if(handleCommentDTO==null || handleCommentDTO.getId()==null || handleCommentDTO.getAction()==null){
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX);
        }
        Comment comment = new Comment();
        comment.setId(handleCommentDTO.getId());
        if(handleCommentDTO.getAction()==1){
            comment.setHideFlag(false);
        }else if(handleCommentDTO.getAction()==2){
            comment.setHideFlag(true);
        }else{
            comment.setIsDelete(true);
        }
        baseMapper.updateById(comment);
        return R.success();
    }

    @Override
    public R<Boolean> comment(Comment comment) {
        if (comment == null || comment.getMid() == null
                || comment.getBizType() == null || comment.getOrderProductId() == null
                || comment.getCommentStar() == null) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX);
        }
        //如果没有设置底部3个星星的数值，则默认为5星好评
        if (comment.getDescStar() == null) {
            comment.setDescStar(5);
        }
        if (comment.getLogisticsStar() == null) {
            comment.setLogisticsStar(5);
        }
        if (comment.getServiceStar() == null) {
            comment.setServiceStar(5);
        }
        if (comment.getBizType() != CommentTypeEnum.NORMAL.getCode()) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX.getCode(), "评价类型不正确");
        }

        /*Integer count = baseMapper.selectCount(Wraps.<Comment>lbQ().eq(Comment::getMid,comment.getMid()).eq(Comment::getOrderProductId,comment.getOrderProductId()));
        if (count > 0) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX.getCode(),"您已评价过该商品，不能再次评价");
        }*/

        //处理敏感词
        Boolean sensitiveFlag = false;
        Boolean hideFlag = false;
        List<CommentSensitiveRelate> relateList = new ArrayList<>();
        SensitiveKeyword sensitiveKeywordSetting = redisRepository.get(CommentConstant.SENSITIVE_KEYWORD_SETTING);
        if(sensitiveKeywordSetting != null && sensitiveKeywordSetting.getEnabled() == 1){
            Set<ZSetOperations.TypedTuple<Object>> keywordSet = redisRepository.getRedisTemplate().opsForZSet().rangeWithScores(CommentConstant.SENSITIVE_LIST,0,-1);
            if(keywordSet!=null){
                Set<String> containsKeywordSet = new HashSet<>();
                Map<String, Long> kewordIdMap = new HashMap<>();
                for(ZSetOperations.TypedTuple<Object> keywordTuple:keywordSet){
                    if(comment.getCommentText().indexOf(keywordTuple.getValue().toString()) != -1){
                        containsKeywordSet.add(keywordTuple.getValue().toString());
                        kewordIdMap.put(keywordTuple.getValue().toString(),keywordTuple.getScore().longValue());
                    }
                }
                if(containsKeywordSet.size()>0){
                    if(sensitiveKeywordSetting.getAction() == SensitiveKeywordAction.FORBID.getCode()){
                        if(containsKeywordSet.size()>5){
                            return R.fail(ExceptionCode.OPERATION_EX.getCode(),"您的评论中包含："+StringUtils.join(containsKeywordSet,",")+"等敏感词，请修改后再提交");
                        }else{
                            return R.fail(ExceptionCode.OPERATION_EX.getCode(),"您的评论中包含以下敏感词，请修改后提交："+StringUtils.join(containsKeywordSet,","));
                        }
                    }else{
                        for(String sensitiveKeyword:containsKeywordSet){
                            CommentSensitiveRelate relate = new CommentSensitiveRelate();
                            relate.setCommentId(comment.getId());
                            relate.setSensitiveKeywordId(kewordIdMap.get(sensitiveKeyword));
                            relateList.add(relate);
                        }
                    }
                    sensitiveFlag = true;
                    hideFlag = true;
                }
            }
        }
        comment.setSensitiveFlag(sensitiveFlag);
        comment.setHideFlag(hideFlag);

        Long opId = comment.getOrderProductId();
        OrderProduct op = orderProductMapper.selectById(opId);
        if (op == null) {
            return R.fail(ExceptionCode.NOT_FOUND.getCode(), "你所评价的订单商品不存在");
        }
        Long orderId = op.getOrderId();
        Order order = orderMapper.selectById(orderId);
        /*if (!order.getMid().equals(comment.getMid())) {
            return R.fail(ExceptionCode.UNAUTHORIZED.getCode(), "你无权评价该商品");
        }*/
        /*if (order.getOrderStatus() != OrderStatusEnum.FINISH.getCode()) {
            return R.fail(ExceptionCode.UNAUTHORIZED.getCode(), "订单未完成，不能评价");
        }*/
        comment.setStoreId(order.getStoreId());
        if (StringUtils.isNotBlank(comment.getCommentImgs())) {
            comment.setCommentImgsFlag(true);
        }
        comment.setProductId(op.getProductId());

        //处理关键词
        List<CommentKeywordRelate> keywordRelateList = new ArrayList<>();
        CommentKeyword commentKeywordSetting = redisRepository.get(CommentConstant.COMMENT_KEYWORD_SETTING);
        if(commentKeywordSetting != null && commentKeywordSetting.getEnabled() == 1){
            Set<ZSetOperations.TypedTuple<Object>> keywordSet = redisRepository.getRedisTemplate().opsForZSet().rangeWithScores(CommentConstant.COMMENT_KEYWORD_LIST,0,-1);
            if(keywordSet!=null){
                Set<String> containsKeywordSet = new HashSet<>();
                Map<String, Long> kewordIdMap = new HashMap<>();
                for(ZSetOperations.TypedTuple<Object> keywordTuple:keywordSet){
                    if(comment.getCommentText().indexOf(keywordTuple.getValue().toString()) != -1){
                        containsKeywordSet.add(keywordTuple.getValue().toString());
                        kewordIdMap.put(keywordTuple.getValue().toString(),keywordTuple.getScore().longValue());
                    }
                }
                if(containsKeywordSet.size()>0){
                    for(String keyword:containsKeywordSet){
                        CommentKeywordRelate relate = new CommentKeywordRelate();
                        relate.setCommentId(comment.getId());
                        relate.setCommentKeywordId(kewordIdMap.get(keyword));
                        keywordRelateList.add(relate);
                    }
                }
            }
        }

        baseMapper.insert(comment);

        //保存评论和敏感词的关联关系
        for(CommentSensitiveRelate relate:relateList){
            relate.setCommentId(comment.getId());
            commentSensitiveRelateMapper.insert(relate);
        }

        //保存和关键词的关系
        for(CommentKeywordRelate keywordRelate:keywordRelateList){
            keywordRelate.setCommentId(comment.getId());
            commentKeywordRelateMapper.insert(keywordRelate);
        }

        return R.success();
    }

    @Override
    public R<Boolean> additionalComment(Comment comment) {
        if (comment == null || comment.getMid() == null
                || comment.getBizType() == null
                || comment.getParentId() == null) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX);
        }

        if (comment.getBizType() != CommentTypeEnum.ADDITIONAL.getCode()) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX.getCode(), "评价类型不正确");
        }

        Integer count = baseMapper.selectCount(Wraps.<Comment>lbQ().eq(Comment::getMid,comment.getMid()).eq(Comment::getParentId,comment.getParentId()));
        if (count > 0) {
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX.getCode(), "您已追评过该评价，不能再次评价");
        }

        //处理敏感词
        Boolean sensitiveAndHideFlag = false;
        List<CommentSensitiveRelate> relateList = new ArrayList<>();
        SensitiveKeyword sensitiveKeywordSetting = redisRepository.get(CommentConstant.SENSITIVE_KEYWORD_SETTING);
        if(sensitiveKeywordSetting != null && sensitiveKeywordSetting.getEnabled() == 1){
            Set<ZSetOperations.TypedTuple<Object>> keywordSet = redisRepository.getRedisTemplate().opsForZSet().rangeWithScores(CommentConstant.SENSITIVE_LIST,0,-1);
            if(keywordSet!=null){
                Set<String> containsKeywordSet = new HashSet<>();
                Map<String, Long> kewordIdMap = new HashMap<>();
                for(ZSetOperations.TypedTuple<Object> keywordTuple:keywordSet){
                    if(comment.getCommentText().indexOf(keywordTuple.getValue().toString()) != -1){
                        containsKeywordSet.add(keywordTuple.getValue().toString());
                        kewordIdMap.put(keywordTuple.getValue().toString(),keywordTuple.getScore().longValue());
                    }
                }
                if(containsKeywordSet.size()>0){
                    if(sensitiveKeywordSetting.getAction() == SensitiveKeywordAction.FORBID.getCode()){
                        if(containsKeywordSet.size()>5){
                            return R.fail(ExceptionCode.OPERATION_EX.getCode(),"您的评论中包含："+StringUtils.join(containsKeywordSet,",")+"等敏感词，请修改后再提交");
                        }else{
                            return R.fail(ExceptionCode.OPERATION_EX.getCode(),"您的评论中包含以下敏感词，请修改后提交："+StringUtils.join(containsKeywordSet,","));
                        }
                    }else{
                        for(String sensitiveKeyword:containsKeywordSet){
                            CommentSensitiveRelate relate = new CommentSensitiveRelate();
                            relate.setCommentId(comment.getId());
                            relate.setSensitiveKeywordId(kewordIdMap.get(sensitiveKeyword));
                            relateList.add(relate);
                        }
                    }
                    sensitiveAndHideFlag = true;
                }
            }
        }
        comment.setSensitiveFlag(sensitiveAndHideFlag);
        comment.setHideFlag(sensitiveAndHideFlag);

        //如果追评有敏感词 主评论也有敏感词
        //如果追评要隐藏，主评论也要隐藏
        if(sensitiveAndHideFlag){
            Comment parentComment = baseMapper.selectById(comment.getParentId());
            if(parentComment != null && !(parentComment.getSensitiveFlag() && parentComment.getHideFlag())){
                parentComment.setSensitiveFlag(true);
                parentComment.setHideFlag(true);
                baseMapper.updateById(parentComment);
            }
        }

        if (StringUtils.isNotBlank(comment.getCommentImgs())) {
            comment.setCommentImgsFlag(true);
        }

        // 追评不用处理关键词
        baseMapper.insert(comment);

        for(CommentSensitiveRelate relate:relateList){
            relate.setCommentId(comment.getId());
            commentSensitiveRelateMapper.insert(relate);
        }

        return R.success();
    }

    @Override
    public R<Boolean> likeOrUnlikeComment(LikeCommentDTO likeCommentDTO) {
        if(likeCommentDTO == null || likeCommentDTO.getMid() == null
            || likeCommentDTO.getAction() == null){
            return R.fail(ExceptionCode.ILLEGALA_ARGUMENT_EX);
        }
        //如果是点赞
        if(likeCommentDTO.getAction() == 1){
            CommentLike commentLike = commentLikeMapper.selectOne(Wraps.<CommentLike>lbQ().eq(CommentLike::getMid,likeCommentDTO.getMid())
                    .eq(CommentLike::getCommentId,likeCommentDTO.getId()));
            if(commentLike == null){
                commentLike = new CommentLike();
                commentLike.setMid(likeCommentDTO.getMid());
                commentLike.setCommentId(likeCommentDTO.getId());
                commentLikeMapper.insert(commentLike);
                baseMapper.increaseLikeNum(likeCommentDTO.getId());
            }
        } else {
            commentLikeMapper.delete(Wraps.<CommentLike>lbQ().eq(CommentLike::getMid,likeCommentDTO.getMid())
                    .eq(CommentLike::getCommentId,likeCommentDTO.getId()));
            baseMapper.decreaseLikeNum(likeCommentDTO.getId());
        }
        return R.success();
    }

    @Override
    public R<CommentPageVO> findMyCommentList(QueryCommentDTO queryCommentDTO) {
        if(queryCommentDTO == null || queryCommentDTO.getMid() == null){
            return R.success(new CommentPageVO());
        }
        if(queryCommentDTO.getType() == null){
            queryCommentDTO.setType(1);
        }
        if(queryCommentDTO.getPageIndex() == null){
            queryCommentDTO.setPageIndex(0);
        }
        if(queryCommentDTO.getPageSize() == null || queryCommentDTO.getPageSize() > 50){
            queryCommentDTO.setPageIndex(10);
        }

        CommentPageVO commentPageVO = new CommentPageVO();
        Integer total = 0;
        Integer containImgTotal = 0;

        Page<Comment> page = new Page<>(queryCommentDTO.getPageIndex(), queryCommentDTO.getPageSize());
        IPage<Comment> pageResult = baseMapper.selectPage(page,Wraps.<Comment>lbQ()
                .eq(Comment::getMid, queryCommentDTO.getMid())
                .eq(Comment::getBizType, CommentTypeEnum.NORMAL.getCode())
                .eq(queryCommentDTO.getType() != null && queryCommentDTO.getType() == 2, Comment::getCommentImgsFlag, true)
                .eq(Comment::getIsDelete,false)
                .orderByDesc(Comment::getCreateTime));

        //如果查全部，还需要知道有图的，有多少，反之，要查全部有多少
        if(queryCommentDTO.getType() == 1){
            total = Long.valueOf(page.getTotal()).intValue();
            containImgTotal = baseMapper.selectCount(Wraps.<Comment>lbQ().eq(Comment::getMid,queryCommentDTO.getMid())
                .eq(Comment::getBizType, CommentTypeEnum.NORMAL.getCode())
                .eq(Comment::getCommentImgsFlag,true)
                .eq(Comment::getIsDelete,false));
        }else{
            total = baseMapper.selectCount(Wraps.<Comment>lbQ()
                    .eq(Comment::getMid,queryCommentDTO.getMid())
                    .eq(Comment::getBizType, CommentTypeEnum.NORMAL.getCode())
                    .eq(Comment::getIsDelete,false));
            containImgTotal = Long.valueOf(page.getTotal()).intValue();
        }
        commentPageVO.setTotal(total);
        commentPageVO.setContainImgTotal(containImgTotal);
        commentPageVO.setCommentVOList(dozerUtils.mapList(pageResult.getRecords(), CommentVO.class));

        //点赞量、我是否已点赞、追评、用户昵称和头像、sku规格字符串
        for(CommentVO commentVO:commentPageVO.getCommentVOList()){
            commentVO.setLikeNum(commentLikeMapper.selectCount(Wraps.<CommentLike>lbQ().eq(CommentLike::getCommentId,commentVO.getId())));
            Integer likedCount = commentLikeMapper.selectCount(Wraps.<CommentLike>lbQ()
                    .eq(CommentLike::getMid,queryCommentDTO.getMid())
                    .eq(CommentLike::getCommentId,commentVO.getId()));
            if(likedCount>=1){
                commentVO.setLiked(true);
            }

            //追评
            Comment additionalComment = baseMapper.selectOne(Wraps.<Comment>lbQ().eq(Comment::getBizType, CommentTypeEnum.ADDITIONAL.getCode())
                    .eq(Comment::getIsDelete, false).eq(Comment::getParentId, commentVO.getId()));
            commentVO.setAdditionalComment(additionalComment);

            //我的评价列表，不需要展示自己的头像和昵称

            //sku的规格值拼接
            OrderProduct op = orderProductMapper.selectById(commentVO.getOrderProductId());
            if(op!=null){
                commentVO.setSkuNameStr(op.getSkuNameStr());
            }

            //设置订单商品对象
            commentVO.setOrderProductVO(dozerUtils.map(op, OrderProductVO.class));
        }

        return R.success(commentPageVO);
    }

    @Override
    public R<CommentPageVO> findProductStoreCommentList(QueryProductOrStoreCommentDTO queryCommentDTO) {
        //进入商详或者店铺，不一定是要登录的
        /*if(queryCommentDTO == null || queryCommentDTO.getMid() == null){
            return R.success(new CommentPageVO());
        }*/
        if(queryCommentDTO.getQueryType() == null){
            queryCommentDTO.setQueryType(1);
        }
        if(queryCommentDTO.getType() == null){
            queryCommentDTO.setType(1);
        }
        if(queryCommentDTO.getPageIndex() == null){
            queryCommentDTO.setPageIndex(0);
        }
        if(queryCommentDTO.getPageSize() == null || queryCommentDTO.getPageSize() > 50){
            queryCommentDTO.setPageIndex(10);
        }

        CommentPageVO commentPageVO = new CommentPageVO();
        Integer total = 0;
        Integer containImgTotal = 0;

        int start = (queryCommentDTO.getPageIndex() - 1) * queryCommentDTO.getPageSize();
        queryCommentDTO.setStart(start);
        List<Comment> commentList = baseMapper.selectListByCondition(queryCommentDTO);

        //如果查全部，还需要知道有图的，有多少，反之，要查全部有多少
        if(queryCommentDTO.getType() == 1){
            total = baseMapper.selectCountByCondition(queryCommentDTO);
            queryCommentDTO.setType(2);
            containImgTotal = baseMapper.selectCountByCondition(queryCommentDTO);
        }else{
            queryCommentDTO.setType(1);
            total = baseMapper.selectCountByCondition(queryCommentDTO);
            queryCommentDTO.setType(2);
            containImgTotal = baseMapper.selectCountByCondition(queryCommentDTO);
        }
        commentPageVO.setTotal(total);
        commentPageVO.setContainImgTotal(containImgTotal);
        commentPageVO.setCommentVOList(dozerUtils.mapList(commentList, CommentVO.class));

        //点赞量、我是否已点赞、追评、用户昵称和头像、sku规格字符串
        for(CommentVO commentVO:commentPageVO.getCommentVOList()){
            commentVO.setLikeNum(commentLikeMapper.selectCount(Wraps.<CommentLike>lbQ().eq(CommentLike::getCommentId,commentVO.getId())));
            Integer likedCount = commentLikeMapper.selectCount(Wraps.<CommentLike>lbQ()
                    .eq(CommentLike::getMid,queryCommentDTO.getMid())
                    .eq(CommentLike::getCommentId,commentVO.getId()));
            if(likedCount>=1){
                commentVO.setLiked(true);
            }

            //追评
            Comment additionalComment = baseMapper.selectOne(Wraps.<Comment>lbQ().eq(Comment::getBizType, CommentTypeEnum.ADDITIONAL.getCode())
                    .eq(Comment::getIsDelete, false).eq(Comment::getParentId, commentVO.getId()));
            commentVO.setAdditionalComment(additionalComment);

            Member member = memberService.getById(commentVO.getMid());
            if(member != null){
                commentVO.setHeadimg(member.getHeadimg());
                commentVO.setNickname(member.getNickname());
            }

            //sku的规格值拼接
            OrderProduct op = orderProductMapper.selectById(commentVO.getOrderProductId());
            if(op!=null){
                commentVO.setSkuNameStr(op.getSkuNameStr());
            }

            //设置订单商品对象
            commentVO.setOrderProductVO(dozerUtils.map(op, OrderProductVO.class));
        }

        List<CommentKeywordVO> commentKeywordVOList = baseMapper.selectTopKeywordList(queryCommentDTO);
        commentPageVO.setCommentKeywordVOList(commentKeywordVOList);

        return R.success(commentPageVO);
    }
    /**
     * App发表评价
     * @param dto
     * @return
     */
    @Override
    public R<Boolean> publishComment(PublishCommentDTO dto) {
        WordContext context = new WordContext();
        WordFilter filter = new WordFilter(context);
        //如果没有设置底部3个星星的数值，则默认为5星好评
        if (dto.getCommentStar() == null) {
            dto.setCommentStar(5);
        }
        if (dto.getServiceStar() == null) {
            dto.setServiceStar(5);
        }
        Boolean s = filter.include(dto.getCommentText());
        if (s) {
            throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "您待发布的内容中内容存在敏感词，请修改后再提交");
        }
        Comment comment = new Comment();
        BeanUtils.copyProperties(dto,comment);
        baseMapper.insert(comment);
        return R.success();
    }

    /**
     * 我的评价
     * @return
     */
    @Override
    public R myComment() {
        Long userId = BaseContextHandler.getUserId();
        return R.success(baseMapper.mycomment(userId));
    }

    @Override
    public R delect(Long id) {
        return R.success(baseMapper.updateDelect(id));
    }
}
